﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ingebet.Model;
using Ingebet.Utils;

namespace Ingebet.Web
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender , EventArgs e)
        {
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            var link = Master.FindControl("btnDeconnexion") as LinkButton;
            link.Visible = false;
        }

        protected void btnEnvoyer_Click(object sender , EventArgs e)
        {
            if (txtEmail.Text != string.Empty)
            {
                try
                {
                    var user = Global.Container.Resolve<UtilisateurModel>().GetByEmail(this.txtEmail.Text);
                    string url = ConfigurationManager.AppSettings["AppliPath"] + @"\Web\Ressource\EmailPassword.tpl";
                    string txt = System.IO.File.ReadAllText(url);
                    string corpsEmail = string.Empty;
                    corpsEmail = txt.Replace("##CIVILITE##" , user.Civilite);
                    corpsEmail = corpsEmail.Replace("##NOM##" , user.Nom);
                    corpsEmail = corpsEmail.Replace("##PRENOM##" , user.Prenom);
                    corpsEmail = corpsEmail.Replace("##PASS##" , user.Password);
                    EmailHelper.SendEmail(this.txtEmail.Text , "Rappel Email Ingebet" , corpsEmail);
                }
                catch (Exception ex)
                {
                    lblError.Text = "Cette adresse email n'existe pas, Veuillez vous s'inscrire ";
                }
            }
        }
    }
}